#include <iostream>
#include <set>
#include <vector>
#include <iterator>
#include <thread>
#include <sw/redis++/redis++.h>


using namespace std;
using namespace sw::redis;


void test(Redis & redis)
{
    cout << "rpush的使用" << endl;
    
    redis.flushall();
    
    redis.rpush("key", {"111", "222", "333"});
    vector<string> v;
    auto it = back_inserter(v);
    redis.lrange("key", 0, -1, it);

    for(auto item : v) {
        cout << "value: " << item <<endl;
    }

}


void test1(Redis& redis)
{
    cout << "expire and ttl" << endl;
    
    redis.flushall();
    
    redis.set("key", "111111111", 10s);

    std::this_thread::sleep_for(4500ms);

    long long result = redis.ttl("key");
    
    cout << "result: " << result << endl;
}   


void test2(Redis& redis)
{
    cout << "blpop " << endl;

    redis.flushall();
    
    auto result = redis.blpop({"key", "key1", "key2", "key3"}, 20s);
    if(result)
    {   
        cout << "key: " << result->first << endl;
        cout << "val: " << result->second << endl;
    }else{
        cout << "返回值无效！！！" << endl;
    }
}


void test3(Redis& redis)
{
    cout << "lrem" << endl;

    redis.flushall();
    redis.rpush("key", {"1", "2", "1", "3", "1"});
    
    auto result = redis.lrem("key", 0, "1");
    cout << "result: " << result << endl;

    vector<string> v;
    auto it = std::back_inserter(v);
    redis.lrange("key", 0, -1, it);

    for(auto item : v)
    {
        cout << "val: " << item <<  endl;
    }
    
}



int main()
{
    Redis redis("tcp://127.0.0.1:6379");
    test3(redis);
    return 0;
}